package com.woniuxy02;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 作者
 * @create 2025-11-13 9:45
 */
public class Test03 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
//        save();
        load();
    }


    private static void load() throws IOException, ClassNotFoundException {
        ObjectInputStream ois=new ObjectInputStream(new FileInputStream("student.bin"));
        Student student = (Student) ois.readObject();
        System.out.println(student);
        ois.close();
    }

    private static void save() throws IOException {
        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("student.bin"));
        Student student=new Student(1,"zs",11,"135");
        oos.writeObject(student);
        oos.close();
    }


    private static void test01() throws IOException, ClassNotFoundException {
//        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("students.bin"));
//        List<Student> students=new ArrayList<>();
//        students.add(new Student(1,"zs",11));
//        students.add(new Student(2,"ls",12));
//        students.add(new Student(3,"ww",13));
//        oos.writeObject(students);
//        oos.close();

        ObjectInputStream ois=new ObjectInputStream(new FileInputStream("students.bin"));
        List<Student> list = (List<Student>) ois.readObject();
        list.forEach(System.out::println);
    }
}
